import service from '@/utils/request'
// import { createService } from '@/utils/request'
import { AxiosResponse } from 'axios'
import qs from 'qs'
import {reqPublishNewType} from "@/api/news/type";

enum API {
    getAllNewsURL = '/news/getAllList',
    publishNewURL = '/news/addNew',
    searchNewsURL = '/news/searchNews',
    getNewsByPageURL = '/news/page',
    getNewsByCategoryURL = '/news/getListByCategoryId/{id}',
    getNewDetailURL = '/news/getDetailById/{id}',
    deleteNewURL = '/news/deleteNew/{id}'
}

//新闻首页获取列表
export const getAllNewsList = () => {
    return service.newsService.get<any,AxiosResponse<any>>(
        API.getAllNewsURL
    )
}
//根据分类获取新闻
export const getNewsByCategory = (id:number) => {
    return service.newsService.get<any,AxiosResponse<any>>(
        API.getNewsByCategoryURL.replace('{id}',id)
    )
}
//搜索获取新闻列表
export const getSearchNewsList = (key: string) => {
    return service.newsService.get<any,AxiosResponse<any>>(
        API.searchNewsURL + '?key=' + key
    )
}
//发布新闻
export const reqPublishNew = (data: reqPublishNewType) => {
    return service.newsService.post<any,AxiosResponse<any>>(
        API.publishNewURL,
        data
    )
}

